package com.bytz.modules.cms.productLine.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bytz.common.system.vo.LoginUser;
import com.bytz.common.util.SecurityUtils;
import com.bytz.modules.cms.productLine.constants.ProductLineConstants;
import com.bytz.modules.cms.productLine.entity.ProductLine;
import com.bytz.modules.cms.productLine.mapper.ProductLineMapper;
import com.bytz.modules.cms.productLine.service.IProductLineService;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * <p>
 * 莱宝CMS—产品线管理—产品线基本信息表 服务实现类
 * </p>
 *
 * @author KyleWang
 * @since 2022-10-10
 */
@Service
public class ProductLineServiceImpl extends ServiceImpl<ProductLineMapper, ProductLine> implements IProductLineService {

    @Override
    public Optional<ProductLine> getLoginUserLine() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if ( SecurityUtils.hasAuthority(ProductLineConstants.Permissions.VIEW_ALL_LINE)) {
            return Optional.empty();
        }
        return lambdaQuery().eq(ProductLine::getDeptId, loginUser.getDeptId()).oneOpt();
    }

    @Override
    public Optional<ProductLine> getByProductLineCode(String lineCode) {
        return lambdaQuery().eq(ProductLine::getProductLineCode, lineCode).oneOpt();
    }

}